<extend name="Base/common"/>

<block name="style">
<link href="__CSS__/stylesheet.css" rel="stylesheet">
<link href="__CSS__/order_cart.css" rel="stylesheet">
</block>

<block name="script">
<script type="text/javascript">
$(function(){
	$('.item_quantity ').change(function(){
		self= $(this);
		_quantity = $(this);
		id = _quantity.attr('data-id');
		price = _quantity.attr('data-price');
		p_total = self.closest('ul').find('.p-total');
		quantity = _quantity.val();			
		productid=_quantity.attr('data-productid');		
		
		if (quantity < 1) {
			quantity = 1;
		}
		
		var url="{:U('modifyQuantity')}";
		$.get(url, {id : id , quantity : quantity, product_id : productid});
	
		total = quantity * price;
		
		_quantity.val(quantity);
		p_total.text(total);
		getSelected();
	});
	
	$('.number-group-addon').click(function(){
		self = $(this);
		_quantity = self.parent().find('input');
		id = _quantity.attr('data-id');
		price = _quantity.attr('data-price');
		p_total = self.closest('ul').find('.p-total');
		quantity = _quantity.val();
		addon = self.attr('addon-sf');
		
		productid=_quantity.attr('data-productid');
		if (addon == '+') {
			quantity++;
		} else if (addon == '-') {
			quantity--;
		} else {
			return;
		}
		
		if (quantity < 1) {
			quantity = 1;
		}
		
		var url="{:U('modifyQuantity')}";
		$.get(url, {id : id , quantity : quantity, product_id : productid});
		
		total = quantity * price;
		
		_quantity.val(quantity);
		p_total.text(total);
		getSelected();
	});
	
	$('.p-list .head .checkbox input').click(function(){
		$(this).closest('li').find('.items input').prop('checked', this.checked);
		getSelected();
	});
	
	$('.list .hd .checkbox input, .list .ft .checkbox input').click(function(){
		$(this).closest('.list').find('input').prop('checked', this.checked);
		getSelected();
	});
	
	$('.items input').change(function(){
		getSelected();
	});
	
	function getSelected(){
		total_quantity = 0;
		total_price = 0;
		
		$.each($('.items .checkbox input'), function(i, item){
			if (item.checked) {
				total_quantity++;
				p_total = $(item).closest('.table').find('.p-total').text();
				p_total = parseFloat(p_total);
				total_price += p_total;
			}
		});
		
		$('.ft .num').text(total_quantity);
		$('.total-price').text(total_price);
	}
});
</script>
</block>

<block name="header">
<header>
	<div class="container">
		<section class="menu-top">
			<div class="fl">
				<section class="header-logo-search">
					<div class="logo fl">
						<img src="__IMG__/logo.png"/>
					</div>
					<div class="search form-group fl">
						<form action="" method="post" autocomplete="off">
							<div class="dropdown fl">
								<a data-toggle="dropdown" href="javascript:;">商品</a>
								<ul class="dropdown-menu">
									<li><a href="javascript:;" data-id="putong">商品</a></li>
									<li><a href="javascript:;" data-id="paipin">拍品</a></li>
									<li><a href="javascript:;" data-id="xianzhi">闲置</a></li>
								</ul>
							</div>
							<input name="type" type="hidden" value="putong">
							<input name="title" type="text" class="search-text" />
							<a href="javascript:;" class="search-btn fr">搜 索</a>
							<script type="text/javascript">
							$(function(){
								$('.dropdown li a').click(function(){
									self = $(this), type = $('.search input[name="type"]');
									$('.dropdown > a').text(self.text());
									type.val(self.attr('data-id'));
								});
							});
							</script>
						</form>
					</div>
				</section>
				<section class="header-ad">
					<img src="__IMG__/header_ad.png">
				</section>
			</div>
	        <div class="fr qrecode">
	            <img src="__IMG__/QRcode.png"/>
	        </div>
        </section>
        <div class="sub-menu fl">
			<a class="sub-menu-top" href="{:U('Product/Index')}">全部商品分类</a>
			<ul class="hidden">
				<volist name=":getCategoryTree()" id='vo'>
					<li>
						<a  class="title" href="{:U('Product/Index?fid='.$vo['id'])}">{$vo.title}</a>
						<div class="sub-menu-list">
							<volist name="vo._child" id="child">
								 <a href="{:U('Product/Index?cid='.$child['id'])}">{$child.title}</a>
					 		</volist>
						</div>
					</li>
				</volist>	
			</ul>
		</div>
		<div class="sub-nav">
	       	<ul>
	       		<li><a href="{:U('Index/index')}">首页</a></li>
	       		<li><a href="{:U('Identify/index')}">鉴真宝</a></li>
	       		<li><a href="{:U('Pzb/index')}">拍真宝</a></li>
	       		<li><a href="{:U('Qgh/index')}">抢购会</a></li>
	       		<li><a href="{:U('Pzg/index')}">拍照购</a></li>
	       		<li><a href="{:U('Xlw/index')}">选礼物</a></li>
	       		<li><a href="{:U('Xz/index')}">闲置</a></li>
	       	</ul>
	    </div>
	</div>
</header>
</block>

<block name="body">
<div class="container main">
	<h3>购物车</h3>
	<form action="{:U('Order/save')}" method="post">
	<div class="list">
		<div class="hd">
			<ul class="table">
				<li><label class="checkbox"><input type="checkbox" class="select-all">全选</label></li>
				<li>商品信息</li>
				<li>单价（元）</li>
				<li>数量</li>
				<li>金额（元）</li>
				<li>操作</li>
			</ul>
		</div>
		<div class="bd">
			<ul class="p-list">
			<volist name="_list" id="list">
				<li>
					<div class="head"><label class="checkbox">
					<input type="checkbox" name="selected">店铺：<span>{$list.shop_title}</span></label></div>
					<ul class="items">
					<volist name="list['product']" id="vo">
						<li>
							<ul class="table">
								<li><label class="checkbox"><input type="checkbox"  name="cartid[]" value="{$vo.cart_id}" name="cartid[]">
								<img src="{$vo.image_path}"></label></li>
								<li><a href="{:U('product/detail',array('id'=>$vo['product_id']))}" class="p-title">{$vo.title}</a></li>
								<li>{$vo.product_price}</li>
								<li>
									<span class="number-group-addon" addon-sf="-">-</span>
									<input type="text"  class="item_quantity input-mini" autocomplete="off" name="quantity" value="{$vo.quantity}" data-productid="{$vo.product_id}" data-id="{$vo.cart_id}" data-price="{$vo.product_price}">
									<span class="number-group-addon" addon-sf="+">+</span>
								</li>
								<li><span class="p-total">{$vo.total_price}</span></li>
								<li><a href="{:U('delcart?id='.$vo['cart_id'])}" class="confirm ajax-get">删除</a></li>
							</ul>
						</li>
						</volist>						
					</ul>
				</li>
			</volist>
			</ul>
		</div>
		<div class="ft">
			<div class="fl">
				<label class="checkbox"><input type="checkbox" class="select-all">全选</label>
			</div>
			<ul class="fr">
				<li>已选商品<em class="num">0</em>件</li>
				<li class="total">合计：（不含运费）</li>
				<li><em class="yen">￥</em><em class="price total-price">0</em></li>
				<li><button class="btn">结算</button></li>
			</ul>
		</div>
	</div>
	</form>
</div>
</block>